//
//  WBComposeTypeView.swift
//  Weibo
//
//  Created by 张俭 on 16/8/19.
//  Copyright © 2016年 张俭. All rights reserved.
//

import UIKit

class WBComposeTypeView: UIView {
    @IBOutlet weak private var dateLabel: UILabel!
    @IBOutlet weak private var weekdayLabel: UILabel!
    @IBOutlet weak private var monthLabel: UILabel!
    @IBOutlet weak private var weatherLabel: UILabel!

    class func composeTypeView() -> WBComposeTypeView {
        let v = UINib(nibName: "WBComposeTypeView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! WBComposeTypeView
        v.frame = UIScreen.main.bounds
        return v
    }
    
    override func awakeFromNib() {
        weatherLabel.text = ""

        let today = Date()
        dateLabel.text = today.day
        weekdayLabel.text = today.weekday
        monthLabel.text = today.string(withFormat: "MM/yyyy")
        WBNetworkManager.shared.loadWeather { (text, temperature) in
            self.weatherLabel.text = "苏州：\(text)  \(temperature)℃"
        }
    }
    
    /// MARK: - 公共方法
    
    /// 显示
    func show() {
        guard let vc = UIApplication.shared.keyWindow?.rootViewController else {
            return
        }
        
        vc.view.addSubview(self)
        
    }

    /// 关闭
    @IBAction private func close() {
        removeFromSuperview()
    }
}
